#include "mouseCursor.h"
#include "GameRes.h"
#include "define.h"

USING_NS_CC;
MouseCursor::MouseCursor()
{

}

MouseCursor::~MouseCursor()
{
	for (auto* ani : _ani) {
		CC_SAFE_RELEASE(ani);
	}
	_ani.clear();
}

bool MouseCursor::init()
{
	if (!Sprite::init()) return false;

	const uint32_t cursor_uid[] = {
		0x535C1994,0x1FBC5273,0xCF1D211E,0xB87E0F0C,
	};
	_ani.resize(sizeof(sizeof(cursor_uid) / sizeof(cursor_uid[0])));
	for (int i = 0;i < (int)_ani.size();++i) {
		_ani[i] = ResManager::GetInstance()->GetAnimate(cursor_uid[i], 10.0f / CONFIG_FPS);
		_ani[i]->retain();
	}
	this->setFlippedY(true);
	_type = 0;
	this->runAction(RepeatForever::create(_ani[_type]));
	_hide = true;
	this->setPosition(-50, -50);
	return true;
}

void MouseCursor::update(float dt)
{

}

void MouseCursor::setCursor(cursor_type type)
{
	this->stopAllActions();
	_type = (int)type;
	this->runAction(RepeatForever::create(_ani[_type]));
}

void MouseCursor::ShowCursor(bool show)
{
	_hide = !show;
	if (_hide) setPosition(-100, -100);
}
